Alibabacloud.com offers a wide variety of articles about javascript string remove all spaces, easily find your javascript string remove all spaces information here online.
I have issued a lot of code to remove spaces from strings, but they all remove the beginning and end. The following code can remove the middle. Javascript trim space removal function implementation code
Http://www.jb51.net/article/16250.htm
The
1. Remove all spaces before and after the string:The code is as follows:Function Trim (str) { Return str. replace (/(^ \ s *) | (\ s * $)/g ,""); }Note:If jQuery is used to directly use the $. trim (str) method, str indicates to remove all
Copy Code code as follows:
Remove the header space of the string (left space)
function LTrim (str) {
var i;
for (i=0;iif (Str.charat (i)!= "") break;
}
str = str.substring (i,str.length);
return str;
}
Remove the trailing
The code is as follows
Copy Code
Remove the header space of the string (left space) function LTrim (str) {var i;for (i=0;iif (Str.charat (i)!= "") break;}str = str.substring (i,str.length);return str;}Remove the trailing space of
How to clear all spaces in a string:About clearing the space at both ends of the string has been introduced, you can see how JavaScript removes the space at both ends of the string chapter, this chapter will explain how to remove all the spaces in
Below I have summarized various methods to delete spaces, including deleting spaces before and after deletion, intermediate spaces, and continuous spaces. For more information, see.
Method 1:
In my opinion, the best method is to use regular
method One: Regular replacement recommendation
Personally think the best way. Using regular expressions, this is the core principle.
The following is the original code
Copy Code code as follows:
Let's take a look at what
Method 1: In my opinion, the best method is to use regular expressions, which is the core principle.Secondly, this method uses the prototype attribute of JavaScript.In fact, you can use functions without using this attribute, but it is more
method One:Personally think the best way. Using regular expressions, this is the core principle.Second, this method uses the prototype properties of JavaScriptIn fact, you do not use this property can be implemented using the function. But this is
Javascript uses regular expressions to remove characters After Spaces
This article describes how to use a regular expression in javascript to remove characters After spaces. For more information, see
When reading data from the backend
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.